local skill = fk.CreateSkill {
  name = "lvshi__lizhan",
}

Fk:loadTranslationTable{
  ["lvshi__lizhan"] = "励战",
  [":lvshi__lizhan"] = "回合结束时，你可观看牌堆顶的四张牌并分配给任意名角色（每名角色至多两张），然后以此法获得牌的角色须使用一张装备牌或弃置一张牌。",
  ["#lvshi__lizhan-give"] = "你可以分配给任意角色，每名角色至多分配两张牌",
  ["#lvshi__lizhan-use"] = "励战：请使用一张装备牌，否则弃置一张牌",

  ["$lvshi__lizhan1"] = "良将如匠，雕朽木为栋，化顽石为铁。",
  ["$lvshi__lizhan2"] = "万卒入伍，练之数旬，余之二三者可称锐。",
}

skill:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(4)
    local targets = {}
    local players = room:getAlivePlayers()
    while not player.dead do
      local tos, cards = room:askToChooseCardsAndPlayers(player, {
        min_num = 1,
        max_num = 1,
        min_card_num = 1,
        max_card_num = 2,
        targets = players,
        pattern = tostring(Exppattern{ id = ids }),
        skill_name = skill.name,
        prompt = "#lvshi__lizhan-give",
        cancelable = true,
        expand_pile = ids,
      })
      if #tos > 0 and #cards > 0 then
        table.insertIfNeed(targets, tos[1])
        for _, id in ipairs(cards) do
          table.removeOne(ids, id)
        end
        table.removeOne(players, tos[1])
        room:moveCardTo(cards, Card.PlayerHand, tos[1], fk.ReasonGive, skill.name, nil, false, player)
        if #ids == 0 then break end
      else
        break
      end
    end
    for _, p in ipairs(targets) do
      if not p.dead then
        local use = room:askToUseRealCard(p, {
          skill_name = skill.name,
          pattern = table.filter(p:getCardIds("h"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end),
          prompt = "#lvshi__lizhan-use",
        })
        if not use then
          player.room:askToDiscard(p, {
            skill_name = skill.name,
            cancelable = false,
            min_num = 1,
            max_num = 1,
            include_equip = true,
          })
        end
      end
    end
  end,
})


return skill
